<?php

namespace App\Kuafu\Order\Enum;

use App\Kuafu\Base\Enum\BaseCodeEnum;

class OrderCacheEnum extends BaseCodeEnum
{
    private const SHOP_TRADE_LOCK = 'shop_trade_lock:%d';

    //pos订单token前缀
    public const PREFIX_ORDER_TOKEN = 'ORDER_TOKEN:';

    private const ORDER_MERCHANT_INDEX     = 'order-merchant-index';
    public const  ORDER_MERCHANT_INDEX_TTL = 300; // 单位秒

    private const ORDER_MERCHANT_ORDERS     = 'order-merchant-orders';
    public const  ORDER_MERCHANT_ORDERS_TTL = 300; // 单位秒

    private const ORDER_MERCHANT_CHARTS     = 'order-merchant-charts';
    public const  ORDER_MERCHANT_CHARTS_TTL = 300; // 单位秒

    private const SHOP_BIND_COUPON_PACKAGE = 'shop-bind-coupon-package:';

    private const COUPON_PACKAGE_NAME_BY_ORDER      = 'coupon-package-name-by-order';
    public const  COUPON_PACKAGE_NAME_BY_ORDER_TTL  = 600; // 单位秒

    /**
     * 店铺交易统计 - 锁
     * @param string $type
     * @return string
     */
    public static function getShopTradeLock(int $shopId): string
    {
        return sprintf(self::SHOP_TRADE_LOCK, $shopId);
    }

    /**
     * 已购买券包统计
     * @param int $shopId
     * @return string
     */
    public static function getCouponPackageNameByOrder(int $shopId): string
    {
        return sprintf(self::COUPON_PACKAGE_NAME_BY_ORDER . ":%d", $shopId);
    }

    /**
     * 商家中心 - 首页缓存
     * @param int $shopId
     * @param int $showStartAt
     * @param int $showEndAt
     * @param int $compareStartAt
     * @param int $compareEndAt
     * @return string
     */
    public static function getOrderMerchantIndex(
        int $shopId,
        int $showStartAt,
        int $showEndAt,
        int $compareStartAt,
        int $compareEndAt
    ): string {
        $str = md5(sprintf(":%d:%d:%d:%d:%d", $shopId, $showStartAt, $showEndAt, $compareStartAt, $compareEndAt));
        return sprintf(self::ORDER_MERCHANT_INDEX . ":%s", $str);
    }

    /**
     * 商家中心 - 店内外订单明细
     * @param int $shopId
     * @param int $showStartAt
     * @param int $showEndAt
     * @param int $orderType
     * @return string
     */
    public static function getOrderMerchantOrders(int $shopId, int $showStartAt, int $showEndAt, int $orderType)
    {
        $str = md5(sprintf(":%d:%d:%d:%d", $shopId, $showStartAt, $showEndAt, $orderType));
        return sprintf(self::ORDER_MERCHANT_ORDERS . ":%s", $str);
    }

    /**
     * 折线图
     * @param int $shopId
     * @param int $startTime
     * @param int $endTime
     * @param int $statisticsType
     * @param int $orderType
     * @return string
     */
    public static function getOrderCharts(
        int $shopId,
        int $startTime,
        int $endTime,
        int $statisticsType,
        int $orderType,
        int $interval,
        int $showTimeTab,
        int $sourceType,
        int $vipIn
    ) {
        $str = md5(sprintf(":%d:%d:%d:%d:%d:%d:%d:%d:%d", $shopId, $startTime, $endTime, $orderType, $statisticsType,
            $interval, $showTimeTab, $sourceType, $vipIn));
        return sprintf(self::ORDER_MERCHANT_CHARTS . ":%s", $str);
    }

    /**
     * 店铺是否绑定券包
     * @param int $shopId
     * @return string
     */
    public static function getShopBindCouponPackage(int $shopId): string
    {
        return sprintf(self::SHOP_BIND_COUPON_PACKAGE . "%d", $shopId);
    }
}
